package com.inspur.his.service.impl;

import com.inspur.his.mapper.PayDetailMapper;
import com.inspur.his.pojo.PayDetail;
import com.inspur.his.service.PayDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class PayDetailServiceImpl implements PayDetailService {

    @Autowired
    private PayDetailMapper payDetailMapper;

    @Override
    public void add(PayDetail payDetail) {
        payDetail.setPayTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        payDetail.setPayType("挂号");
        payDetailMapper.add(payDetail);
    }

    @Override
    public List<PayDetail> show(String memberId, String payType, int currPage, int pageSize) {
        HashMap map = new HashMap<>();
        int startNum = (currPage - 1) * pageSize;
        map.put("startNum", startNum);
        map.put("pageSize", pageSize);
        map.put("memberId", memberId);
        map.put("payType", payType);
        return payDetailMapper.show(map);
    }

    @Override
    public int count(String memberId, String payType) {
        HashMap map = new HashMap<>();
        map.put("memberId", memberId);
        map.put("payType", payType);
        return payDetailMapper.count(map);
    }

    @Override
    public void delete(Integer id) {
        payDetailMapper.delete(id);
    }

    @Override
    public void update(PayDetail payDetail) {
        payDetailMapper.update(payDetail);
    }

    @Override
    public PayDetail getOneById(Integer id) {
        return payDetailMapper.getOneById(id);
    }
}
